<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Field;
use App\Models\Booking;
use App\Models\BookingField;


class BookingController extends Controller
{
    public function index(Request $request)
    {
        $fields = Field::where(['status'=>1])->get();
    	return view('booking.index',compact('fields'));
    }

    public function save(Request $request)
    {
        $task['code']   = date('YmdHis').mt_rand(10,99);
        $wechat_user    = session('wechat.oauth_user.default');      
        $task['openid'] = object_get($wechat_user,'id','11');
        $t = Booking::create($task);
        $fields = $request->except(['_method','_token']);
       
        foreach ($fields as $k => $v) {
            
            $data['booking_id'] = $t->id;
            $data['field_id'] = explode('_', $k)[1];
            $data['value'] = $v;
            BookingField::create($data);
        }
        
    }

   

    

   

    
}
